package com.example.toolproject.demo.util.excel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * @ClassName Convert
 * @Description TODO
 * @Author lvyongwei
 * @Date 2020-06-19 21:42
 * @Version 1.0
 **/
public class Convert implements Converter<Integer> {

    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if(cellData.getStringValue().equals("文献库")){
            return 1;
        }else if(cellData.getStringValue().equals("媒体库")){
            return 2;
        }else if(cellData.getStringValue().equals("建筑专题")){
            return 3;
        }else if(cellData.getStringValue().equals("名人专题")){
            return 4;
        }else if(cellData.getStringValue().equals("特产专题")){
            return 5;
        }else if(cellData.getStringValue().equals("非物质文化")){
            return 6;
        } else{
            return 0;
        }
    }

    @Override
    public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if(integer==1){
            return new CellData("文献库");
        }else if(integer==2){
            return new CellData("媒体库");
        }else if(integer==3){
            return new CellData("建筑专题");
        }else if(integer==4){
            return new CellData("名人专题");
        }else if(integer==5){
            return new CellData("特产专题");
        } else if(integer==6){
            return new CellData("非物质文化");
        }
        return new CellData("null");
    }
}

